﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Common.Utilities;
using Common.Utilities.Dispatcher;
using Workflows.Components.ETL.Properties;

namespace Workflows.Components.ETL
{
    ///<summary>
    ///</summary>
    [Serializable]
    public class DataSamplerComponent:WorkflowComponentBase
    {
        /// <summary>
        /// 
        /// </summary>
        public DataSamplerComponent():base()
        {
            this.ComponentActivityType = WorkflowActivityType.SimpleActivity;
            this.ComponentCategory = WorkflowComponentCategory.ETL.ToString();
            this.Description = "Sample data";
            this.ComponentIcon = Resources._16_Defragment;
            this.ComponentImage = Resources.TxDerived_201;
            this.ComponentName = "Sample Data";

            this._Instruction = new DataSamplerInstruction(this.ComponentID, Guid.Empty,string.Empty,string.Empty,
                new List<string>(), new Dictionary<string, List<string>>(), 
                SamplingMethod.Count, 500, string.Empty, string.Empty, 
                new Dictionary<string, string>(),
                new Dictionary<string, Dictionary<object, int>>(),
                new Dictionary<string, string>(),
                new Dictionary<string, AggregateFunction>(), 
                new Dictionary<string, string>(), string.Empty);
            this._Output=new DataSamplerOutput(this.ComponentID,Guid.Empty,string.Empty);
        }

        #region Overrides of WorkflowComponentBase

        private DataSamplerInstruction _Instruction;
        /// <summary>an object that encapsulate instruction settings.</summary>
        public override InstructionBase Instruction
        {
            get { return _Instruction; }
            set { _Instruction =(DataSamplerInstruction)value; }
        }

        private DataSamplerOutput _Output;
        /// <summary>an object to encapsulate output</summary>
        public override ResultBase Output
        {
            get { return _Output; }
            set { _Output=(DataSamplerOutput)value; }
        }

        #endregion

        public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
        {
            XmlNode xNode = base.Serialize(ref xDoc, ref parentNode);
            this.Instruction.Serialize(ref xDoc, ref xNode);
            return xNode;
        }

        public override WorkflowComponentBase Instantiate(XmlNode xNode)
        {
            DataSamplerComponent component = (DataSamplerComponent)base.Instantiate(xNode);
            component.Instruction = component.Instruction.Instantiate(xNode.SelectSingleNode("Instruction"));
            return component;
        }
    }
}
